package com.zsk.mybaits.demo.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.jws.soap.SOAPBinding.Use;

import org.apache.catalina.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import com.zsk.mybaits.demo.dao.IUserDao;
import com.zsk.mybaits.demo.vo.UserVO;

/**
 * @author keke
 * @date 2021/08/07
 */
@RestController
public class TestController {

    @Resource
    private IUserDao useDao;

    @GetMapping("/findUser")
    public List<UserVO> findUser(String id) {
        UserVO user = new UserVO();
        user.setId("4e72a2c9-8924-4969-a57d-4d0e9af39649");
        user.setName(id);
        if (id.equals("123")) {
            throw new RuntimeException("事务测试");
        }
        //useDao.updateById(user);
        return useDao.findById(id);
    }

    @PostMapping("/updateUser")
    public int update(@RequestBody UserVO user) {
        int res = useDao.updateById(user);
        if (user.getNumber() == null) {
            throw new RuntimeException("更新事务异常");
        }
        return res;
    }

}
